<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of MetadaController
 *
 * @author Lisette
 */
class MetadaController extends BaseController{
    //put your code here
    
    private function bind(){
        $metadata = new Metadata();
        empty($_POST['authors']) ? $metadata->setAuthors("") : $metadata->setAuthors($_POST['authors']);
        empty($_POST['authors']) ? $metadata->setAutorsAscii("") : $metadata->setAutorsAscii(utf8_deaccent($_POST['authors']));
        empty($_POST['affiliation']) ? $metadata->setAffiliation("") : $metadata->setAffiliation($_POST['affiliation']);
        empty($_POST['title']) ? $metadata->setTitle("") : $metadata->setTitle($_POST['title']);
        empty($_POST['title']) ? $metadata->setTitleAscii("") : $metadata->setTitleAscii(utf8_deaccent($_POST['title']));
        empty($_POST['journal_abbr']) ? $metadata->setJournal("") : $metadata->setJournal($_POST['journal_abbr']); //journal_abr2 ?
        empty($_POST['secondary_title']) ? $metadata->setSecondaryTitle("") : $metadata->setSecondaryTitle($_POST['secondary_title']); //secondary title 2 ?
        empty($_POST['year']) ? $metadata->setYear("") : $metadata->setYear($_POST['year']);
        empty($_POST['abstract']) ? $metadata->setAbstract("") : $metadata->setAbstract($_POST['abstract']);
        empty($_POST['abstract']) ? $metadata->setAbstractAscii("") : $metadata->setAbstractAscii(utf8_deaccent($_POST['abstract']));
        empty($_POST['rating']) ? $metadata->setRating("2") : $metadata->setRating($_POST['rating']);
        empty($_POST['volume']) ? $metadata->setVolume("") : $metadata->setVolume($_POST['volume']);
        empty($_POST['issue']) ? $metadata->setIssue("") : $metadata->setIssue($_POST['issue']);
        empty($_POST['pages']) ? $metadata->setPages("") : $metadata->setPages($_POST['pages']);
        empty($_POST['editor']) ? $metadata->setEditor("") : $metadata->setEditor($_POST['editor']);
        empty($_POST['url'][0]) ? $metadata->setUrl("") : $metadata->setUrl(join('|', array_filter($_POST['url'])));
        empty($_POST['reference_type']) ? $metadata->setReferenceType("") : $metadata->setReferenceType($_POST['reference_type']);
        empty($_POST['publisher']) ? $metadata->setPublisher("") : $metadata->setPublisher($_POST['publisher']);
        empty($_POST['place_published']) ? $metadata->setPlacePublished("") : $metadata->setPlacePublished($_POST['place_published']);
        empty($_POST['doi']) ? $metadata->setDoi("") : $metadata->setDoi($_POST['doi']);
        empty($_POST['custom1']) ? $metadata->setCustom1("") : $metadata->setCustom1($_POST['custom1']);
        empty($_POST['custom2']) ? $metadata->setCustom2("") : $metadata->setCustom1($_POST['custom2']);
        empty($_POST['custom3']) ? $metadata->setCustom3("") : $metadata->setCustom1($_POST['custom3']);
        empty($_POST['custom4']) ? $metadata->setCustom4("") : $metadata->setCustom1($_POST['custom4']);
                
        if($_POST['keywords'])
            $metadata->setKeywords("");
        else {
            $keywords = $_POST['keywords'];
	    empty($_POST['keyword_separator']) ? $keyword_separator = '/' : $keyword_separator = $_POST['keyword_separator'];
            $keyword_array = explode($keyword_separator, $keywords);
            function trim_value(&$value) { $value = trim($value); }
            array_walk($keyword_array, 'trim_value');
            $keywords = implode(' / ', $keyword_array);            
            $metadata->setKeywords($keywords);
        }
        return $metadata;
    }
}

?>
